package com.tongtong.stscommon.exception.controller;

import com.tongtong.stscommon.exception.*;
import com.tongtong.stscommon.message.STSErrorMessage;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;

/**
 * 全局异常处理器
 */
@ControllerAdvice
@RestController
public class GlobalExceptionController {

	// 七牛云上传失败异常
	@ExceptionHandler(STSQiniuOperationException.class)
	public STSErrorMessage handleSTSUploadFileException(STSQiniuOperationException ex) {
		return new STSErrorMessage(ex.getErrorCode(), ex.getMessage());
	}

	// 文件类型异常
	@ExceptionHandler(STSFileValidationException.class)
	public STSErrorMessage handleSTSFileValidationException(STSFileValidationException ex) {
		return new STSErrorMessage(ex.getErrorCode(), ex.getMessage());
	}

	// 鉴权异常
	@ExceptionHandler(STSAuthenticationException.class)
	public STSErrorMessage handleSTSAuthenticationException(STSAuthenticationException ex) {
		return new STSErrorMessage(ex.getErrorCode(), ex.getMessage());
	}

	// 注册异常
	@ExceptionHandler(STSRegisterException.class)
	public STSErrorMessage handleSTSRegisterException(STSRegisterException ex) {
		return new STSErrorMessage(ex.getErrorCode(), ex.getMessage());
	}

	// 资源操作异常
	@ExceptionHandler(STSResourcesOperationException.class)
	public STSErrorMessage handleSTSResourcesOperationException(STSResourcesOperationException ex) {
		return new STSErrorMessage(ex.getErrorCode(), ex.getMessage());
	}

	// 手机号异常
	@ExceptionHandler(STSPhoneNumberValidationException.class)
	public STSErrorMessage handleSTSPhoneNumberValidationException(STSPhoneNumberValidationException ex) {
		return new STSErrorMessage(ex.getErrorCode(), ex.getMessage());
	}

	// 订单异常
	@ExceptionHandler(STSOrderOperationException.class)
	public STSErrorMessage handleSTSOrderOperationException(STSOrderOperationException ex) {
		return new STSErrorMessage(ex.getErrorCode(), ex.getMessage());
	}

	// 审核异常
	@ExceptionHandler(STSAuditedException.class)
	public STSErrorMessage handleSTSAuditedException(STSAuditedException ex) {
		return new STSErrorMessage(ex.getErrorCode(), ex.getMessage());
	}
}
